import util from '../../common/js/util'
import NProgress from 'nprogress'
import axios from 'axios';
import address from "../../../models/dict/address"
import moment from 'moment'
import dContract from '../../../models/dict/dContract';
const dCustomerOrder = require('../../../models/dict/customerOrder');
import customerOrderShow from '../Order/customerOrderShow.vue'
import Vue from 'vue';
const yz = require('../../../models/comm/yz');

export default {
    data() {
        return {
            contractList: [],
            currObj: {},
            customerOrderList: [],
            customerOrderDetail: [],
            showCustomerOrder: false


        }
    },
    methods: {
        //性别显示转换
        getContract: function () {


            if (this.contractId == "" || this.currObj == null) {
                this.currObj = dContract.fmtContract();
                return
            }
            axios.post("/a", {
                class: "contract",
                para: "getContract",
                j: {
                    _id: this.contractId
                }

            }).then((res) => {

                if (!res.data.class) {
                    res.data.class = [];

                }

                Vue.set(this, "currObj", dContract.fmtContract(res.data.info))

                this.getCustomerOrderList()
                this.ShowSave = true;

            });

        },

        getStatusName(statusId) {
            return dContract.getStatusName(statusId);
        },
        getCustomerOrderList() {

            this.listLoading = true;
            NProgress.start();
            axios.post("/a", {
                class: "customerOrder",
                para: "getCustomerOrderList",
                j: {
                    data: {
                        "contractInfo._id": this.currObj._id
                    }
                }

            }).then((res) => {


                res.data.list.forEach(function (element) {



                    dCustomerOrder.fmtCustomerOrder(element)

                    element.show = false
                }, this);
                Vue.set(this, "customerOrderList", res.data.list)



            });
        },
        getModelNo(c) {
            return dCustomerOrder.getModelNo(c)

        },
        getCustomerOrder(row) {

            this.customerOrder = row;
            this.customerOrderDetail = dCustomerOrder.fmtDetalType(this.customerOrder)

            this.showCustomerOrder = true
        },
        getDateStr(date) {
            return moment(date).format("YYYY-MM-DD HH:mm");

        },
        getSettlementStatusName(statusId) {
            return dContract.getStatusName(statusId)
        },

        reItem(row, index) {
            axios.post("/a", {
                class: "customerOrder",
                para: "reItem",
                j: {

                    "customerOrderId": this.customerOrder._id,
                    "item": row
                }

            }).then((res) => {
                if (res.err) {
                    this.$notify.error({
                        title: '错误',
                        message: res.err
                    });
                }
                else {
                    this.getContract()
                    Vue.set(this.customerOrderDetail, index, res.data.item)

                }




            });
        },
        reAll() {  //全部到账


        }

    },
    props: [
        "contractId"
    ],


    mounted() {
        this.getContract();
    },
    watch: {
        contractId: function name(params) {



            console.log("contractId变动" + this.contractId);
            this.getContract();
        }
    },
    components: {
        customerOrderShow
    }

}